package com.example.annolog.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class ThreadPoolLogic {
    final static Logger logger = LoggerFactory.getLogger(ThreadPoolLogic.class);

    @Resource
    private TaskExecutor normalTaskExecutor;

    public void execute(AbstractCommonThread commonThread) {
        executeDo(commonThread, false);
    }

    private void executeDo(AbstractCommonThread commonThread,
                           boolean withException) {
        String threadPoolType = commonThread.getThreadType();
        try {
            executeDo(commonThread, threadPoolType);
        } catch (Exception e) {
            logger.error("线程池[{}]添加任务失败，请技术人员核查",
                    AbstractCommonThread.ThreadTypeEnum.getNameByCode(threadPoolType), e);
        }
    }

    private void executeDo(AbstractCommonThread commonThread,
                           String threadPoolType) {
        normalTaskExecutor.execute(commonThread);
    }

}



